{ ETP Link minishrt sell 170222 }
i1(
ppnat=or(ge(xtime(d,m),1),ge(xtime(date(),h),10))
lt1=lasttrade(b,d)
lt2=lasttrade(s,d)
minSedanKp=mult(sub(date(),lt1),1440)
minSedanSlj=mult(sub(date(),lt2),1440)
tid_ok=and(ppnat,and(gt(minSedanKp,0.33),gt(minSedanSlj,0.33)))
cell=scrpar(32)
insats=scrpar(21)
replikera=eqv(insats,0)
id_ok=and(ge(cell,10),le(cell,799))

include=scrpar(30)
wanted_price=getgvar(add(cell,1000))
best_match=getgvar(add(5000,cell))
keep_paper=or(not(include),or(and(eqv(best_match,crcid()),and(include,wanted_price)),not(wanted_price)))
sync1=and(and(eqv(xtime(date(),m),59),ge(xtime(date(),s),30)),le(xtime(date(),h),16))

antal=if(and(keep_paper,lt(getgvar(cell),0)),abs(getgvar(cell)),0)
adjust1=gt(portfolio(v),antal)
adjust2=and(gt(portfolio(v),0),le(antal,0))
samma_dag=eqv(int(d),int(date()))
slj=and(and(and(if(replikera,adjust1,adjust2),samma_dag),tid_ok),id_ok)
Mult(slj,10)
)